home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1999 Spring / macformat-077.iso / Shareware Plus / Development / Akua Sweets 131 / Akua Sweets Examples / Network / Remote / Remote Dup < prev    next >
Encoding:
Text File  |  1999-03-04  |  3.4 KB  |  124 lines  |  [TEXT/ToyS]

  1. -- Internal/User setable globals
  2. property gasLinkSet : false -- Has the friend been asked for?
  3. property gasLinkNeed : true
  4. property kasLinkUserDft : "CasaVision" -- Our friend on all machines
  5. property kasLinkPassDft : "" -- Our friend's password on all machines
  6.  
  7. -- Internal globals
  8. global gasLinkUser --
  9. global gasLinkPass -- 
  10.  
  11. global gasOurZone -- Set to zone of gasOurAlias
  12. global gasOurServer -- Set to server of gasOurAlias
  13. global gasOurName -- Name of application on remote server
  14. global gasOurAction -- Set to choice of user (quit, shutdown, restart)
  15.  
  16.  
  17. on open fsObjs
  18.     repeat with fsObj in fsObjs
  19.         set f to (fsObj as string) as alias -- Some weird stuff, I know...
  20.         
  21.         set fileLoc to alias info from (f as alias)
  22.         
  23.         set gasOurName to original name of fileLoc
  24.         set gasOurServer to alias server of fileLoc
  25.         set gasOurZone to alias zone of fileLoc
  26.         
  27.         set fileVol to alias volume of fileLoc
  28.         set volAlias to (fileVol & ":") as alias
  29.         
  30.         GetFriend(false)
  31.         
  32.         talk as user gasLinkUser ¬
  33.             with password gasLinkPass ¬
  34.             on server gasOurServer ¬
  35.             in AppleTalk zone gasOurZone
  36.         
  37.         tell application "Finder" of machine gasOurServer of zone gasOurZone to ¬
  38.             set newFile to duplicate f -- to volAlias
  39.     end repeat
  40. end open
  41.  
  42.  
  43.  
  44.  
  45. on GetFriend(override) -- Should later use some modifier key to override?!?
  46.     if (gasLinkNeed) then GetOneFriend(override)
  47. end GetFriend
  48.  
  49.  
  50. on GetOneFriend(override)
  51.     set isLink to true -- Only linking in this script!
  52.     set userMode to "linking"
  53.     set defUser to kasLinkUserDft
  54.     set defPass to kasLinkPassDft
  55.     set passButtons to {"Cancel", "OK"}
  56.     set passButton to 2
  57.     
  58.     set usrPwd to KeyChainLookUp(gasOurZone, gasOurServer, isLink)
  59.     
  60.     if (override or usrPwd is {}) then
  61.         set chosen to display dialog ¬
  62.             "Enter the friendly " & userMode & ¬
  63.             " user's name…" default answer defUser ¬
  64.             default button 2 with icon note
  65.         
  66.         if (the button returned of chosen is "OK") then
  67.             set defUser to the text returned of chosen
  68.         else
  69.             return
  70.         end if
  71.         
  72.         set chosen to display dialog ¬
  73.             "Enter the friendly " & userMode & ¬
  74.             " user's password…" buttons passButtons ¬
  75.             default answer defPass default button passButton with icon note
  76.         
  77.         if (the button returned of chosen is not "Cancel") then
  78.             set defPass to the text returned of chosen
  79.         else
  80.             return
  81.         end if
  82.         
  83.         -- Save encrypted user/pass for future access
  84.         KeyChainSave(gasOurZone, gasOurServer, isLink, defUser, defPass, "")
  85.     else
  86.         set defUser to item 1 of usrPwd
  87.         set defPass to item 2 of usrPwd
  88.     end if
  89.     
  90.     set gasLinkSet to true
  91.     set gasLinkUser to defUser
  92.     set gasLinkPass to defPass
  93. end GetOneFriend
  94.  
  95.  
  96. property kasKeyChainPassword : "PowerScript" -- Encrypt stored data with this
  97. property kasPrefsFileName : "PowerScript Prefs" -- File name in <Preferences>
  98.  
  99. on KeyChainLookUp(zoneName, serverName, isLinking)
  100.     set prefOwner to "πSRV"
  101.     if (isLinking) then set prefOwner to "πLNK"
  102.     
  103.     try
  104.         set myKeyData to load preference named (zoneName & ":" & serverName) ¬
  105.             of type prefOwner in file named kasPrefsFileName
  106.     on error
  107.         return {}
  108.     end try
  109.     
  110.     return (encrypt the data myKeyData with password kasKeyChainPassword)
  111. end KeyChainLookUp
  112.  
  113.  
  114. on KeyChainSave(zoneName, serverName, isLinking, usr, pwd, ntPwd)
  115.     set myKey to encrypt the data {usr, pwd, ntPwd} with password kasKeyChainPassword
  116.     
  117.     set prefOwner to "πSRV"
  118.     if (isLinking) then set prefOwner to "πLNK"
  119.     
  120.     save preference myKey named (zoneName & ":" & serverName) ¬
  121.         of type prefOwner ¬
  122.         in file named kasPrefsFileName
  123. end KeyChainSave
  124.